package domain.entities;

import java.util.Date;
import java.util.List;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * ProtocoloCentro entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see domain.entities.ProtocoloCentro
 * @author MyEclipse Persistence Tools
 */

public class ProtocoloCentroDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(ProtocoloCentroDAO.class);
	// property constants
	public static final String ACTIVATION_TO_FPFV = "activationToFpfv";
	public static final String ACTIVE_PATIENTS = "activePatients";
	public static final String ADDITIONAL_APPROVAL = "additionalApproval";
	public static final String AREA = "area";
	public static final String CCIS = "ccis";
	public static final String COMMENTS = "comments";
	public static final String CTAG_SEND_EXEC = "ctagSendExec";
	public static final String ENROLLED_PATIENTS = "enrolledPatients";
	public static final String ESPECIALIDAD = "especialidad";
	public static final String INSPECTION_AUDIT = "inspectionAudit";
	public static final String IP_SENT_TO_IRB = "ipSentToIrb";
	public static final String JUSTIFICACION = "justificacion";
	public static final String PROTOCOLO_CENTROCENTROID = "protocoloCentrocentroid";
	public static final String PROTOCOLO_CENTROPROTOCOLOID = "protocoloCentroprotocoloid";
	public static final String RANDOMIZED_PATIENTS = "randomizedPatients";
	public static final String RECRUITMENT_COMMITED = "recruitmentCommited";
	public static final String RECRUITMENT_RANDOMIZED = "recruitmentRandomized";
	public static final String SELECCIONADO = "seleccionado";
	public static final String SITE_NUMBER = "siteNumber";
	public static final String SPECIAL_RECRUITMENT_ACTIONS = "specialRecruitmentActions";
	public static final String TARGET_PATIENTS = "targetPatients";

	protected void initDao() {
		// do nothing
	}

	public void save(ProtocoloCentro transientInstance) {
		log.debug("saving ProtocoloCentro instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ProtocoloCentro persistentInstance) {
		log.debug("deleting ProtocoloCentro instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ProtocoloCentro findById(domain.entities.ProtocoloCentroId id) {
		log.debug("getting ProtocoloCentro instance with id: " + id);
		try {
			ProtocoloCentro instance = (ProtocoloCentro) getHibernateTemplate()
					.get("domain.entities.ProtocoloCentro", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<ProtocoloCentro> findByExample(ProtocoloCentro instance) {
		log.debug("finding ProtocoloCentro instance by example");
		try {
			List<ProtocoloCentro> results = (List<ProtocoloCentro>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ProtocoloCentro instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ProtocoloCentro as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<ProtocoloCentro> findByActivationToFpfv(Object activationToFpfv) {
		return findByProperty(ACTIVATION_TO_FPFV, activationToFpfv);
	}

	public List<ProtocoloCentro> findByActivePatients(Object activePatients) {
		return findByProperty(ACTIVE_PATIENTS, activePatients);
	}

	public List<ProtocoloCentro> findByAdditionalApproval(
			Object additionalApproval) {
		return findByProperty(ADDITIONAL_APPROVAL, additionalApproval);
	}

	public List<ProtocoloCentro> findByArea(Object area) {
		return findByProperty(AREA, area);
	}

	public List<ProtocoloCentro> findByCcis(Object ccis) {
		return findByProperty(CCIS, ccis);
	}

	public List<ProtocoloCentro> findByComments(Object comments) {
		return findByProperty(COMMENTS, comments);
	}

	public List<ProtocoloCentro> findByCtagSendExec(Object ctagSendExec) {
		return findByProperty(CTAG_SEND_EXEC, ctagSendExec);
	}

	public List<ProtocoloCentro> findByEnrolledPatients(Object enrolledPatients) {
		return findByProperty(ENROLLED_PATIENTS, enrolledPatients);
	}

	public List<ProtocoloCentro> findByEspecialidad(Object especialidad) {
		return findByProperty(ESPECIALIDAD, especialidad);
	}

	public List<ProtocoloCentro> findByInspectionAudit(Object inspectionAudit) {
		return findByProperty(INSPECTION_AUDIT, inspectionAudit);
	}

	public List<ProtocoloCentro> findByIpSentToIrb(Object ipSentToIrb) {
		return findByProperty(IP_SENT_TO_IRB, ipSentToIrb);
	}

	public List<ProtocoloCentro> findByJustificacion(Object justificacion) {
		return findByProperty(JUSTIFICACION, justificacion);
	}

	public List<ProtocoloCentro> findByProtocoloCentrocentroid(
			Object protocoloCentrocentroid) {
		return findByProperty(PROTOCOLO_CENTROCENTROID, protocoloCentrocentroid);
	}

	public List<ProtocoloCentro> findByProtocoloCentroprotocoloid(
			Object protocoloCentroprotocoloid) {
		return findByProperty(PROTOCOLO_CENTROPROTOCOLOID,
				protocoloCentroprotocoloid);
	}

	public List<ProtocoloCentro> findByRandomizedPatients(
			Object randomizedPatients) {
		return findByProperty(RANDOMIZED_PATIENTS, randomizedPatients);
	}

	public List<ProtocoloCentro> findByRecruitmentCommited(
			Object recruitmentCommited) {
		return findByProperty(RECRUITMENT_COMMITED, recruitmentCommited);
	}

	public List<ProtocoloCentro> findByRecruitmentRandomized(
			Object recruitmentRandomized) {
		return findByProperty(RECRUITMENT_RANDOMIZED, recruitmentRandomized);
	}

	public List<ProtocoloCentro> findBySeleccionado(Object seleccionado) {
		return findByProperty(SELECCIONADO, seleccionado);
	}

	public List<ProtocoloCentro> findBySiteNumber(Object siteNumber) {
		return findByProperty(SITE_NUMBER, siteNumber);
	}

	public List<ProtocoloCentro> findBySpecialRecruitmentActions(
			Object specialRecruitmentActions) {
		return findByProperty(SPECIAL_RECRUITMENT_ACTIONS,
				specialRecruitmentActions);
	}

	public List<ProtocoloCentro> findByTargetPatients(Object targetPatients) {
		return findByProperty(TARGET_PATIENTS, targetPatients);
	}

	public List findAll() {
		log.debug("finding all ProtocoloCentro instances");
		try {
			String queryString = "from ProtocoloCentro";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

    public List<ProtocoloCentro> findByProtocoloCompromisopais(ProtocoloCompromisopais pcp){
        log.debug("finding all ProtocoloCentro instances");
        try {
            String queryString = "from ProtocoloCentro where protocolo_compromisopaiscompromisopaisid = " + pcp.getCompromisopais().getId() + " and protocolo_compromisopaisprotocoloid = '" + pcp.getProtocolo().getId() + "'";
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

	public ProtocoloCentro merge(ProtocoloCentro detachedInstance) {
		log.debug("merging ProtocoloCentro instance");
		try {
			ProtocoloCentro result = (ProtocoloCentro) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ProtocoloCentro instance) {
		log.debug("attaching dirty ProtocoloCentro instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ProtocoloCentro instance) {
		log.debug("attaching clean ProtocoloCentro instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProtocoloCentroDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (ProtocoloCentroDAO) ctx.getBean("ProtocoloCentroDAO");
	}
}